<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
		<!-- Google Chrome Frame也可以让IE用上Chrome的引擎: -->
		<meta name="renderer" content="webkit">
		<!--国产浏览器高速模式-->
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="description" content="网站简介" />
		<!-- 网站简介 -->
		<meta name="keywords" content="搜索关键字，以半角英文逗号隔开" />
		<title>车辆位置定位</title>
		
		<!-- 公共样式 开始 -->
		<link rel="stylesheet" type="text/css" href="../../css/base.css">
		<link rel="stylesheet" type="text/css" href="../../css/iconfont.css">
		<script type="text/javascript" src="../../framework/jquery-1.11.3.min.js"></script>
		<link rel="stylesheet" type="text/css" href="../../layui/css/layui.css">
		<script type="text/javascript" src="../../layui/layui.js"></script>
		<!-- 滚动条插件 -->
		<link rel="stylesheet" type="text/css" href="../../css/jquery.mCustomScrollbar.css">
		<script src="../../framework/jquery-ui-1.10.4.min.js"></script>
		<script src="../../framework/jquery.mousewheel.min.js"></script>
		<script src="../../framework/jquery.mCustomScrollbar.min.js"></script>
		<script src="../../framework/cframe.js"></script><!-- 仅供所有子页面使用 -->
		<!-- 公共样式 结束 -->
	</head>

	<body>
		<div class="backRoleSysModel-con">
				<div class="layui-form-item">
					<form class="layui-form" action="">
					  <div class="layui-form-item" >
					   <br>
						  <!--    <div class="layui-input-inline">
								<input style="width:200px;" type="text" name="selectname" id="selectname" class="layui-input">
							</div>
							<div class="layui-inline">
								<button id="btnselbackrole" type="button"class="layui-btn layuiadmin-btn-useradmin layui-btn-radius">查询</button>
							</div>-->
							<div class="layui-inline" style="margin-left:20px;">
								<button class="layui-btn layuiadmin-btn-useradmin layui-btn-radius" type="button"id="btn_income">添加</button>
							</div>
					  </div>
					</form>
				</div>
				
			<table class="layui-hide" id="Rolemodel" lay-filter="Rolemodel"></table>
			<script type="text/html" id="barDemo"> 
					  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
					  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
	        </script>
			<script type="text/html" id="selectbar">
					<input type="checkbox" name="{{d.deepth}}" value="{{d.id}}" title="授予" lay-filter="lockDemo" {{ d.isedit == "1" ? 'checked' : '' }}>
			</script>
	
			<script type="text/html" id="menuTypebar">
					<span>{{ d.deepth <= "1" ? '展开菜单' : '子菜单' }}</span>
			</script>
			</div>
	
			<!--角色内容  -->
			<div id="div_addmajor" style="display: none;text-align: center; ">
				<form class="layui-form" action="">
					<br>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px;">编号</label>
							<div class="layui-input-inline shortInput">
								<input type="text" name="Rolename" id="Rolename" required lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px;">车牌号</label>
							<div class="layui-input-inline shortInput">
								<input type="text" name="deepth" id="deepth" required lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px;">经度</label>
							<div class="layui-input-inline shortInput">
								<input type="text" name="description" id="description" required lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px;">纬度</label>
							<div class="layui-input-inline shortInput">
								<input type="text" name="deepth" id="deepth" required lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px;">创建时间</label>
							<div class="layui-input-inline shortInput">
								<input type="text" name="parentid" id="parentid" required lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px;">备注</label>
							<div class="layui-input-inline shortInput">
								<input type="text" name="parentid" id="parentid" required lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<button class="layui-btn" lay-submit lay-filter="submitBut" id="btn_addroler">立即提交</button>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
				</form>
		</div>
		  <script src="../../js/Bookkeep.js"></script>
		<script src="framework/area.js"></script>
		<script src="framework/province.js"></script>
			<script>
		//查询开始
	layui.use([ 'table', 'form', 'layer',  'laytpl', 'element' ], function() {
			var table = layui.table, form = layui.form, 
				layer = layui.layer, $ = layui.jquery,
				element = layui.element;
				
			/*加载表格*/
			table.render({
				elem : '#Rolemodel',
				id:'Rolemodel',
				url : 'role/getrolelistByPage',
				title : '',
				height : "full-160",
				skin : 'line',
				curr:1,
				even : true,
				cols : [ 
				     [{
						field : 'mapnumid',
						align : 'center',
						title : '编号',
						
					},
				     {
						field : 'carid',
						align : 'center',
						title : '车牌',
						
					}, {
						field : 'longitude',
						align : 'center',
						title : '经度',
							
					},
					{
						field : 'latitude',
						align : 'center',
						title : '纬度',
							
					},
					{
						field : 'createdate',
						align : 'center',
						title : '创建时间',
							
					},
					{
						field : 'mapnumnote',
						align : 'center',
						title : '备注',
							
					},
					 {
							title: '操作',
							toolbar: '#barDemo',
							align: 'center',
							width : 180
						}] 
				 ],
				page: {
						layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
						groups: 5,
						limit: 10,
						limits: [10, 20, 30, 40, 50],
						theme: '#1E9FFF',						
				 }
			});
			
			//条件查询
			$("#btnselbackrole").click(function(){
	   		var selectname=$("#selectname").val().trim();
	   		var param = '?selectname='+selectname;
	   		alert(param);
	   		table.render({
				elem : '#departmentlist',
				id:'departmentlist',
				url : 'role/getrolelistByPage' + param,
				title : '',
				height : "full-160",
				skin : 'line',
				curr:1,
				even : true,
				cols : [ 
				     [{
						field : 'roleid',
						align : 'center',
						title : '角色编号',
						
					},
				     {
						field : 'rolename',
						align : 'center',
						title : '角色名称',
						
					}, {
						field : 'description',
						align : 'center',
						title : '角色描述',
							
					},
					{
						field : 'createtime',
						align : 'center',
						title : '创建时间',
							
					},
					{
						field : 'deepth',
						align : 'center',
						title : '深度',
							
					},
					{
						field : 'parentid',
						align : 'center',
						title : '父级ID',
							
					},
					 {
							title: '操作',
							toolbar: '#barDemo',
							align: 'center',
							width : 180
						}] 
				 ],
				page: {
						layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
						groups: 5,
						limit: 10,
						limits: [10, 20, 30, 40, 50],
						theme: '#1E9FFF',						
				 }
			});
	   });
			
			table.on('tool(Rolemodel)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
			  var data = obj.data; //获得当前行数据
			  var layEvent = obj.event;
			  //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
			  var tr = obj.tr; //获得当前行 tr 的DOM对象
			  if(layEvent == 'del'){ //删除
			    layer.confirm('真的删除行么', function(index){
			      obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
			      layer.close(index);
			      //向服务端发送删除指令
			      	$.post("role/deleterole",{roleid:obj.data.roleid},function(flag){
		    			if(flag){
		    				layer.msg("刪除成功",{icon:6}); //表格刷新
					        table.reload('Rolemodel'); //重载表格	
		    			}else{
		    				layer.msg("刪除失敗",{icon:5});
		    			}
			    	});
			    });
			   } else if(layEvent == 'edit'){ //编辑
			    //do something
			   //脚本编辑弹出层
		             var name = encodeURIComponent(data.toolName);
		             //alert(name);
		             layer.open({
			               type: 2,
			               title: '修改信息',
			               shadeClose: true,
			               shade: 0.5,
			               closeBtn:'1',//右上角xx关闭
			               area: ['500px','500px'],
			               content:'edit_Role.jsp',
			               btn: ['确定', '取消'],
			               yes: function(index, layero){
				           //点击确认触发 iframe 内容中的按钮提交
				           var submit = layero.find('iframe').contents().find("#btn_update");
				           submit.click();
				           //表格刷新
			          	   table.reload('Rolemodel');
				        },
			               success : function(layero, index){
					            var body = layui.layer.getChildFrame('body', index);
					            if(layEvent == 'edit'){
					                // 取到弹出层里的元素，并把编辑的内容放进去
					                body.find("#Roleid").val(obj.data.roleid);  //将选中的数据的id传到编辑页面的隐藏域，便于根据ID修改数据
					                body.find("#Rolename").val(obj.data.rolename); 
					                body.find("#description").val(obj.data.description);
					                body.find("#createtime").val(obj.data.createtime);
					                body.find("#deepth").val(obj.data.deepth);
					                 body.find("#parentid").val(obj.data.parentid);
					                // 记得重新渲染表单
			                		form.render();
					            }
					            setTimeout(function(){
					                layui.layer.tips('点击此处返回用户列表', '.layui-layer-setwin .layui-layer-close', {
					                    tips: 3
					                });
					            },100)
					        }
		             });
		              //同步更新缓存对应的值
			    obj.update({
			      username: '123'
			      ,title: 'xxx'
			    });
			  }
			});		
		//查询结束
		
		//添加一条方法开始
		$("#btn_addroler").click(function(){
				var Rolename=$("#Rolename").val();
				var description=$("#description").val();
			
				var deepth=$("#deepth").val();	
				var parentid=$("#parentid").val();			
				var obj = {
							"Rolename":Rolename,
							"description":description,
							
							"deepth":deepth,	
							"parentid":parentid,						
							};
				$.ajax({
						url : 'role/addRole',
						type : "POST",
						data : obj, //直接传对象参数 
						dataType : 'json',
						success : function(data) {
								alert("添加成功!");
						},
						error:function(){
		    	        	$("#input").val("");
		    	        }  
					});	
				});
			});
			//添加结束
	  </script>
	</body>

</html>
